{include /common/header}
<script>
	function file_upload(){
		var file = event.target.files[0];
		// 判断是否图片
		if(!file) return ;

		var reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function(e){
			$.ajax({
				url: '{:\mylib\Route::buildUrl('/admin/api/upload')}',
				type: 'POST',
				dataType: 'json',
				data: {
					name:file.name,
					file_data:reader.result
				},
				success:function(res){
					if (res.code) {
						$('#upload_xx').val(res.data.filename);
					}else{
						alert(res.message);
					}
				},
				error:function(){
					alert('系统繁忙！');
				}
			});
		}
	}
	function upload_trigger(){
		document.getElementById('upload_form').reset();
		document.getElementById('upload_input').click();
		return false;
	}
</script>
<form id="upload_form" style="display: none;">
	<input type="file" id="upload_input" onchange="file_upload()">
</form>
<form action="{:\mylib\Route::buildUrl('/admin/block/add')}" method="POST">
	<fieldset>
		<legend>新增碎片</legend>

		<div class="form-group">
			<label>分组</label>
			<input type="text" class="form-control" name="group" value="" required>
		</div>

		<div class="form-group">
			<label>标题</label>
			<input type="text" class="form-control" name="title" value="" required>
		</div>

		<div class="form-group">
			<label>名称</label>
			<input type="text" class="form-control" name="name" value="" required>
			<span class="help-block">英文字符</span>
		</div>

		<div class="form-group">
			{switch $type}
				{case 'text'}
				<label>文本</label>
				<textarea class="form-control" name="value" rows="5"></textarea>
				{/case}

				{case 'editor'}
				<label>内容</label>
				<textarea name="value" rows="8" class="form-control xheditor {urlType:'abs',html5Upload:true,upMultiple:true,upLinkUrl:'{:\mylib\Route::buildUrl('/admin/api/xhupload')}',upLinkExt:'zip,rar,txt',upImgUrl:'{:\mylib\Route::buildUrl('/admin/api/xhupload')}',upImgExt:'jpg,jpeg,gif,png',upFlashUrl:'{:\mylib\Route::buildUrl('/admin/api/xhupload')}',upFlashExt:'swf',upMediaUrl:'{:\mylib\Route::buildUrl('/admin/api/xhupload')}',upMediaExt:'avi'}"></textarea>
				{/case}

				{case 'upload'}
				<label>附件</label>
				<div class="input-group">
					<input type="text" class="form-control" name="value" value="" id="upload_xx" placeholder="">
					<span class="input-group-btn">
						<button class="btn btn-default" type="button" onclick="upload_trigger()">上传</button>
					</span>
				</div>
				{/case}

				{case 'tpl'}
				<label>模板</label>
				<textarea class="form-control" name="value" rows="5"></textarea>
				<span class="help-block">支持模板标签 支持php代码</span>
				{/case}
			{/switch}
		</div>

		<div class="form-group">
			<label>缓存有效期</label>
			<input type="number" class="form-control" name="expire" value="3600" required>
			<span class="help-block">0表示不缓存 单位秒</span>
		</div>

		<div class="form-group">
			<label>备注</label>
			<input type="text" class="form-control" name="tips" value="">
		</div>

		<input type="hidden" name="type" value="{$type}">
		<button type="submit" class="btn btn-primary">提交</button>
	</fieldset>
</form>
{include /common/footer}